package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.dm.DmDealUser
import com.cheyun.netsalev3.utils.api.*
import com.cheyun.netsalev3.utils.api.dm.DmApiCallback
import com.cheyun.netsalev3.utils.api.dm.DmApiException
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class DmClueTransferActivityRepository(var clueId:String) {
    /**
     * 线索移交
     */
    fun clueTransfer(toUserId:String,toUser:String,remark:String, method: () -> Unit) {
        DmApiClient.getInstance().clueTransfer(clueId,toUserId,toUser,remark)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DmApiCallback<DmBaseResp<Int,Any>>() {
                    override fun onSuccess(t: DmBaseResp<Int,Any>) {
                        method()
                    }
                    override fun onError(ex: DmApiException) {

                    }
                })
    }

    fun getDealusers(method: (List<DmDealUser>) -> Unit){
        DmApiClient.getInstance().getDealUsers()
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DmApiCallback<DmBaseResp<List<DmDealUser>,Any>>() {
                    override fun onSuccess(t: DmBaseResp<List<DmDealUser>,Any>) {
                        t.list?.apply {
                            method(t.list!!)
                        }
                    }
                    override fun onError(ex: DmApiException) {

                    }
                })
    }

    fun clueFollow(status:String,type:String,arrive:String,dealTime:String,remark:String, method: () -> Unit,fail:(String)->Unit) {
        DmApiClient.getInstance().clueFollow(clueId,status,type,arrive,dealTime,remark)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : DmApiCallback<DmBaseResp<Int,Any>>() {
                    override fun onSuccess(t: DmBaseResp<Int,Any>) {
                        method()
                    }
                    override fun onError(ex: DmApiException) {
                        fail(ex.getMessage()!!);
                    }
                })
    }


}